package com.cloud.system.common.utils;

import com.cloud.system.api.entity.DynamicUnitExcel;

import java.util.ArrayList;
import java.util.List;


public class Pager {

    /**
     * 当前页码
     */
    private static int currentPage;
    /**
     * 总页数
     */
    private int totalPage;
    /**
     * 总行数
     */
    private static int total;
    /**
     * 每页显示条数
     */
    private static int avgRows = 15;
    /**
     * 原集合
     */
    private static List list;

    private int pageSize;

    public Pager() {
        super();
    }

    public Pager(int currentPage, List list) {
        super();
        this.currentPage = currentPage;
        this.list = list;
        this.total = list.size();
        this.pageSize = list.size();
        this.totalPage = (this.total - 1) / this.avgRows + 1;
    }

    public static List getPagerList() {
        List newList = new ArrayList();
        for(int i = (currentPage - 1) * avgRows; i < total && i < currentPage * avgRows; i++) {
            newList.add(list.get(i));
        }
        return newList;
    }

    public int getCurrentPage() {
        return currentPage;
    }
    public void setCurrentPage(int currentPage) {
        this.currentPage = currentPage;
    }
    public int getTotalPage() {
        return totalPage;
    }
    public void setTotalPage(int totalPage) {
        this.totalPage = totalPage;
    }
    public int getAvgRows() {
        return avgRows;
    }
    public void setAvgRows(int avgRows) {
        this.avgRows = avgRows;
    }

    public int getTotal() {
        return total;
    }

    public void setTotal(int total) {
        this.total = total;
    }

    public int getPageSize() {
        return pageSize;
    }

    public void setPageSize(int pageSize) {
        this.pageSize = pageSize;
    }

    public List getList() {
        return list;
    }

    public void setList(List list) {
        this.list = list;
    }

    public static void main(String[] args) {
        List<Integer> integers = new ArrayList<Integer>();
        for(int i=0;i<99;i++){
            integers.add(i);
        }
//        List<DynamicUnitExcel> integers = new ArrayList<>();
//        for(int i=0;i<99;i++){
//            DynamicUnitExcel excel = new DynamicUnitExcel();
//            excel.setHuman(Integer.toString(i));
//            integers.add(excel);
//        }

        Pager pager = new Pager(1,  integers);
        System.out.println(pager);
    }

    @Override
    public String toString() {
        System.out.println("currentPage="+this.currentPage);
        System.out.println("avgRows="+this.avgRows);
        System.out.println("totalPage="+this.totalPage);
        System.out.println("total="+this.total);
        System.out.println("pageSize="+this.pageSize);
        for(Object i:this.getPagerList()){
            System.out.print(i+",");
        }
        return super.toString();
    }


}